<template>
  <div :class="['BottomNavigationBar', SideLeftMeShow ? 'show' : 'hide']">
    <div @click="navigate('/pages/BookCase')" class="item">
      <em
        :class="['iconfont', 'icon-a-wenjianshuben']"
        :style="{ color: current == 0 ? '#fe537a' : '#423d5b' }"
      ></em>
      <span
        class="title"
        :style="{ color: current == 0 ? '#fe537a' : '#423d5b' }"
        >书架</span
      >
    </div>

    <div @click="navigate('/pages/BookCity')" class="item">
      <em
        :class="['iconfont', 'icon-faxian1']"
        :style="{ color: current == 1 ? '#fe537a' : '#423d5b' }"
      ></em>
      <span
        class="title"
        :style="{ color: current == 1 ? '#fe537a' : '#423d5b' }"
        >书城</span
      >
    </div>

    <div @click="navigate('/pages/BookCabinet')" class="item">
      <em
        :class="['iconfont', 'icon-wodepinglun']"
        :style="{ color: current == 2 ? '#fe537a' : '#423d5b' }"
      ></em>
      <span
        class="title"
        :style="{ color: current == 2 ? '#fe537a' : '#423d5b' }"
        >书阁</span
      >
    </div>

    <div @click="navigate('/pages/BookStore')" class="item">
      <em
        :class="['iconfont', 'icon-zuanshihuiyuan-line']"
        :style="{ color: current == 3 ? '#fe537a' : '#423d5b' }"
      ></em>
      <span
        class="title"
        :style="{ color: current == 3 ? '#fe537a' : '#423d5b' }"
        >有狐慧</span
      >
    </div>
  </div>
</template>

<script>
import { useIndex } from "../stores/index.js";
import { computed, toRefs } from "vue";
import {  useRoute } from "vue-router";
export default {
  // 接收参数
  props: ["current"],
  setup(props) {
    const indexStore = useIndex();
    
    // 结构参数
    let { current } = toRefs(props);
    
    // const router = useRouter();
    const route = useRoute();

    let navigate = (path)=>{
      // console.log(route.path);
      // 如果已经在本页面就不重定向
      if(path !== route.path){
        // router.push(path);
        // router.replace()
        uni.redirectTo({
          url:path
        })
      }
    }

    return {
      SideLeftMeShow: computed(() => indexStore.SideLeftMeShow),
      current,
      navigate,
    };
  },
};
</script>

<style lang="scss" scoped>
.BottomNavigationBar {
  height: 54px;
  position: fixed;
  left: 0;
  right: 0;
  margin: auto;
  min-width: 320px;
  max-width: 750px;
  bottom: 0;
  width: 100%;
  display: flex;
  align-items: center;
  box-shadow: 0 -1px 6px 1px rgba($color: #000000, $alpha: 0.1);
  transition: all 0.3s ease;
  z-index: 10;
  background-color: #fff;

  &.show {
    left: calc(100% - 80px);
  }

  &.hide {
    left: 0;
  }

  .item {
    flex: 1;
    display: flex;
    align-items: center;
    flex-direction: column;
    transition: all 0.3s ease;

    &:active {
      transform: scale(0.9);
      opacity: 0.7;
      text-shadow: 0 0 15px #fe537a;
    }

    &:nth-child(1) {
      .iconfont {
        font-size: 20px;
        font-weight: bold;
      }
    }

    &:nth-child(2) {
      .iconfont {
        font-weight: bold;
        font-size: 24px;
      }
    }

    &:nth-child(3) {
      .iconfont {
        font-weight: bold;
      }
    }

    &:nth-child(4) {
      .iconfont {
        font-weight: bold;
      }
    }

    .iconfont {
      display: block;
      font-size: 22px;
      height: 24px;
      display: flex;
      align-items: center;
      color: #423d5b;
    }
    .title {
      display: block;
      margin-top: 5px;
      color: #423d5b;
      font-size: 12px;
    }
  }
}
</style>